/*
 * @Author: Setsuna
 * @Email: setsuna.xyz@qq.com
 * @FilePath: \src\pages\SystemMasterDataManage\MaterialManagement\List\Approve.tsx
 * @Date: 2023-05-16 16:06:18
 * @LastEditTime: 2023-05-23 22:11:26
 * @LastEditors: Setsuna
 */
import ProcessList from '@/components/ProcessList'
import React, { Component } from 'react'
import { http, UdDrawer } from '@/lib'
import { Empty, Spin, Transfer, message } from 'antd'
import apis from '@/apis/SystemMasterDataManage'
import './index.scss'

interface IProps {
  rows: any
  onRefresh: any
}

export class StocksApprovalProcess extends Component<IProps> {
  state = {
    loading: false,
    mockData: [],
    targetKeys: [],
  }
  componentDidMount() {
    this.getStocksApprovalProcess()
  }
  private handleChange = (newTargetKeys: string[]) => {
    this.setState(
      {
        targetKeys: newTargetKeys,
      },
      () => {
        console.log(this.state.targetKeys)
        this.forceUpdate()
      }
    )
  }

  private getStocksApprovalProcess = () => {
    let {
      rows: { brandCode, processKeys },
    } = this.props
    if (processKeys) this.setState({ targetKeys: processKeys.split(',') })
    this.setState({
      loading: true,
    })
    http
      .get(apis.workflow, {
        params: { brandCode },
      })
      .then(res => {
        let { data } = res
        data.map(e => {
          e.title = e.processName
          e.key = e.processKey
          e.chosen = true
        })
        this.setState({ mockData: data, loading: false })
      })
      .finally(() => {
        this.setState({ loading: false })
      })
  }
  private onOk = e => {
    const { targetKeys } = this.state
    let {
      rows: { id },
    } = this.props
    http
      .post(apis.udpateProductGroup, {
        id: id,
        processKeys: targetKeys.join(','),
      })
      .then(res => {
        message.success('操作成功')
        this.props.onRefresh()
        e.drawerBtnLoading()
        e.close()
      })
      .catch(err => {})
  }
  render() {
    return (
      <Spin spinning={this.state.loading}>
        <div style={{ minHeight: 400 }}>
          <Transfer
           titles={['是', '否']}
            dataSource={this.state.mockData}
            targetKeys={this.state.targetKeys}
            onChange={this.handleChange}
            render={item => item.title}
          />
        </div>
      </Spin>
    )
  }
}

export default StocksApprovalProcess
